package com.zx.eval.api.admin;

import java.util.*;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zx.common.utils.Constant;
import com.zx.common.utils.ShiroUtils;
import com.zx.sys.user.api.AbstractApi;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zx.eval.entity.EvalTableEntity;
import com.zx.eval.service.EvalTableService;
import com.zx.common.utils.PageUtils;
import com.zx.common.utils.R;



/**
 *
 *
 * @author LiYe@zx
 * @email ily_hxy@163.com
 * @date 2020-03-29 18:17:26
 */
@RestController
@RequestMapping("eval/evaltable")
public class EvalTableApi{
    @Autowired
    private EvalTableService evalTableService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("eval:evaltable:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = evalTableService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("eval:evaltable:info")
    public R info(@PathVariable("id") Integer id){
		EvalTableEntity evalTable = evalTableService.getById(id);

        return R.ok().put("info", evalTable);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("eval:evaltable:save")
    public R save(@RequestBody EvalTableEntity evalTable){
        Long userId = ShiroUtils.getUserId();
        evalTable.setCreateTime(new Date());
        evalTable.setCreator(userId);
		evalTableService.save(evalTable);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("eval:evaltable:update")
    public R update(@RequestBody EvalTableEntity evalTable){
        Long userId = ShiroUtils.getUserId();
        evalTable.setUpdateTime(new Date());
        evalTable.setUpdater(userId);
		evalTableService.updateById(evalTable);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("eval:evaltable:delete")
    public R delete(@RequestBody Integer[] ids){
		evalTableService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 获取下拉选择框
     */
    @RequestMapping("/select")
    @RequiresPermissions("eval:evaltable:list")
    public R select(@RequestParam Map<String, Object> params) {
        return R.ok().put("list", evalTableService.list());
    }

    @RequestMapping("/category")
    @RequiresPermissions("eval:evaltable:list")
    public R selectCategoryTable(@RequestParam Map<String, Object> params){
        QueryWrapper<EvalTableEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lt("category", 3);
        queryWrapper.eq("display", 1);
        queryWrapper.orderByAsc("priority");
        List<EvalTableEntity> list = evalTableService.list(queryWrapper);
        return R.ok().put("info", list);
    }

}
